﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Data.SqlClient;
using BioModel;

namespace BioDAL
{
    [DataContract]
    public class BiografDal : IBiografDAL
    {
        
        #region Connection
        private SqlConnection sqlCn = null;

        public void OpenConnection(string connectionString)
        {
            Console.WriteLine("Connection Established");
            sqlCn = new SqlConnection();
            sqlCn.ConnectionString = connectionString;
            sqlCn.Open();
        }

        public void CloseConnection()
        {
            sqlCn.Close();
        }
        #endregion

        //#region BilletSalg
        //public int InsertBilletSalg(DateTime salgDato)
        //{
        //    try
        //    {
        //        string sql = string.Format("Insert into bioBilletSalg" +
        //             "(salgDato) Values" +
        //             "('{0}')", salgDato);

        //        using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
        //        {
        //            cmd.ExecuteNonQuery();
        //        }
        //    }
        //    catch (SqlException se)
        //    {
        //        Console.Write("!SQL Insert Film error " + se);

        //    }
        //    return GetMaxId("salgId", "bioBilletSalg");
        //}
        //#endregion

        //#region Betaling
        //public int InsertBetaling(DateTime betalingsDato, bool betalingsStatus)
        //{
        //    try
        //    {
        //        string sql = string.Format("Insert into bioBetaling" +
        //             "(betalingsDato,betalingsStatus) Values" +
        //             "('{0}', '{1}')", betalingsDato, betalingsStatus);

        //        using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
        //        {
        //            cmd.ExecuteNonQuery();
        //        }
        //    }
        //    catch (Exception se)
        //    {
        //        Console.WriteLine("!SQL Insert Betaling fejl: " + se);
        //    }
        //    return GetMaxId("betalingsId", "bioBetaling");
        //}
        //#endregion

        //#region Reservation
        //public int InsertReservation(DateTime reservationsDato, int kundeTlf)
        //{
        //    try
        //    {
        //        string sql = string.Format("Insert into bioReservation" +
        //             "(reservationsDato,kundeTlf) Values" +
        //             "('{0}', '{1}')", reservationsDato, kundeTlf);

        //        using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
        //        {
        //            cmd.ExecuteNonQuery();
        //        }
        //    }
        //    catch (Exception se)
        //    {
        //        Console.WriteLine("!SQL Insert reservation fejl: " + se);
        //    }
        //    return GetMaxId("reservationsId", "bioReservation");
        //}

        //private static Reservation BuildReservation(SqlDataReader dr)
        //{
        //    return new Reservation(
        //                            (DateTime)(dr["reservationsDato"]),
        //                            (int)(dr["kundeTlf"]));
        //}

        //public Reservation GetReservation(int kundeTlf)
        //{
        //    Reservation kunde = new Reservation();
        //    string sql = string.Format("Select * from bioReservation where kundeTlf = {0}", kundeTlf);
        //    using (SqlCommand cmd = new SqlCommand(sql, this.sqlCn))
        //    {
        //        SqlDataReader dr = cmd.ExecuteReader();
        //        while (dr.Read())
        //        {
        //            kunde = BuildReservation(dr);
        //        }
        //        dr.Close();
        //    }
        //    return kunde;
        //}   
        //#endregion

        
    }
}
